package com.hy.demo.learn.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * <p>
 *
 * </p>
 *
 * @author cjl
 * @version 1.0
 * @since 2020-07-30 09:21
 */
public class FutureTaskDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        FutureTask<String> task=new FutureTask<String>(new CallableDemo());
//        new Thread(task).start();
//        if (!task.isDone()){
//            System.out.println("Work Is Not Done Please Wait");
//        }
//        System.out.println(task.get());

        ExecutorService executorService= Executors.newCachedThreadPool();
        FutureTask<String> task= (FutureTask<String>) executorService.submit(new CallableDemo());
        System.out.println(task.get());
        executorService.shutdown();
    }
}
